#include "stdafx.h"
#include <windows.h>
#include "RSCOMPRESS.h"

RSZLIB::RSZLIB(void)
{
	pcom=puncom=NULL;
	pcombound=NULL;

	hdll = LoadLibrary("zlib1.dll"); 

	if (!hdll) 
		return ;

	pcom = (PCOM)GetProcAddress(hdll,"compress"); 
	puncom=(PUNCOM)GetProcAddress(hdll,"uncompress"); 
	pcombound=(PCOMBOUND)GetProcAddress(hdll,"compressBound"); 
}

RSZLIB::~RSZLIB(void)
{
	if(hdll!=NULL)
		FreeLibrary(hdll);
}

int RSZLIB::Compress(BYTE *dest,UINT *destLen,const BYTE *source,UINT sourceLen)
{
	return pcom(dest,(ULONG *)destLen,source,sourceLen);
}

int RSZLIB::UnCompress(BYTE *dest,UINT *destLen,const BYTE *source,UINT sourceLen)
{
	return puncom(dest,(ULONG *)destLen,source,sourceLen);
}

UINT RSZLIB::GetBound(UINT len)
{
	return pcombound(len);
}

RSLZMA::RSLZMA()
{
	pcom=NULL;
	puncom=NULL;
	propsize=5;
	props[0]=93;
	props[1]=props[2]=props[3]=0;
	props[4]=1;
	//pcombound=NULL;

	hdll = LoadLibrary("LZMA.dll"); 

	if (!hdll) 
		return ;

	pcom = (PCOMLZMA)GetProcAddress(hdll,"LzmaCompress"); 
	puncom=(PUNCOMLZMA)GetProcAddress(hdll,"LzmaUncompress"); 
	//pcombound=(PCOMBOUND)GetProcAddress(hdll,"compressBound"); 
}

RSLZMA::~RSLZMA(void)
{
	if(hdll!=NULL)
		FreeLibrary(hdll);
}

int RSLZMA::Compress(BYTE *dest,UINT *destLen,const BYTE *source,UINT sourceLen)
{
	return pcom(dest,destLen,source,sourceLen,props,&propsize,5,(1 << 24),3,0,2,32,1);
}

int RSLZMA::UnCompress(BYTE *dest,UINT *destLen,const BYTE *source,UINT sourceLen)
{
	return puncom(dest,destLen,source,&sourceLen,props,propsize);
}
